//
//  ListTableViewCell.m
//  jingdongfang
//
//  Created by 郝志宇 on 16/8/10.
//  Copyright © 2016年 ZhiYu Hao. All rights reserved.
//

#import "ListTableViewCell.h"
#import "OrderDetailModel.h"

@interface ListTableViewCell ()
{
    UIImageView *imageView;
    UILabel *name;
    UILabel *type;
    UILabel *price;
    UILabel *num;
}

@end

@implementation ListTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self _initViews];
    }
    return self;
}

- (void)_initViews
{
    self.contentView.backgroundColor = [UIColor c2Color];
    imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    imageView.clipsToBounds = YES;
    [self.contentView addSubview:imageView];
    
    name = [[UILabel alloc] initWithFrame:CGRectZero];
    name.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:name];
    
    type = [[UILabel alloc] initWithFrame:CGRectZero];
    type.font = [UIFont systemFontOfSize:13];
    type.textColor = [UIColor grayColor];
    [self.contentView addSubview:type];
    
    price = [[UILabel alloc] initWithFrame:CGRectZero];
    price.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:price];
    
    num = [[UILabel alloc] initWithFrame:CGRectZero];
    num.font = [UIFont systemFontOfSize:12];
    num.textColor = [UIColor grayColor];
    [self.contentView addSubview:num];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    if([self.backColor integerValue]==0){
        self.contentView.backgroundColor=[UIColor c3Color];
    }
    if([self.backColor integerValue]==1)
    {
        self.contentView.backgroundColor = [UIColor c2Color];
    }
        if ([self.data isMemberOfClass:[OrderDetailModel class]])
        {
        OrderDetailModel *info = self.data;
        [imageView sd_setImageWithURL:[NSURL URLWithString:info.image] placeholderImage:[UIImage imageNamed:@"new"]];
//        [imageView sd_setImageWithURL:[NSURL URLWithString:info.image]];
        imageView.frame = CGRectMake(15, 15, self.height-30, self.height-30);
        
        name.text = info.title?:NSLocalizedString(@"Item Name", nil);
        [name sizeToFit];
        name.x = imageView.right + 10;
        name.y = imageView.top + 5;
        name.width = 150;
//        type.text = @"限量收藏-电子版";
//        if ([info.type integerValue]==2) {
//            type.text = @"购买艺术品";
//        } else if ([info.type integerValue]==4) {
//            type.text = @"购买画屏配件";
//        } else
        if ([info.type integerValue]==1) {
//            type.text = @"限量收藏-电子版";
            type.text = NSLocalizedString(@"Limited Collection-E-copy", nil);
        }else{
            type.text=info.typeTitle;
        }
        [type sizeToFit];
        type.x = imageView.right + 10;
        type.top = name.bottom + 5;
        
        price.text = [@"￥" stringByAppendingString:info.price.length>0?info.price:@"0"];
        [price sizeToFit];
        price.right = self.width - 15;
        price.centerY = name.centerY;
        
        num.text = info.num ? [NSString stringWithFormat:@"x%@", info.num] : @"x1";
        [num sizeToFit];
        num.right = price.right;
        num.centerY = type.centerY;
    }
}

- (void)awakeFromNib
{
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

@end
